levls = c(0.10,0.05,0.01) #nominal levels of the test
nvec=c(200,400,600,800) #sample sizes
gamvec=seq(0,1,by=0.2) #tuning the deviation away from the null
Sig.X = 0.25^as.matrix(dist(1:5)) #covariance matrix for generating instruments
Sig.U = 0.25^as.matrix(dist(1:2)) #covariance matrix for 1st & 2nd stage
bet = eta = rep(1,ncol(Sig.X)) #vector of coefficients on X and transforms of Z
#generate auxiliary variables for the bootstrap; n=400 fixed
wmat400=wmat.mammen(n=nvec[2],B=B,seed = 2)
Kernels=c("Gauss","Euclid") # ICM kernels to consider
cl = floor(detectCores()/2) #number of cores to use in parallel computation
#===============================================================================
source("JT05_Fonctions.R")
source("JT06_Fonctions_Sim.R")
list.files()
#===============================================================================
MCOBJ.Gauss_5p=MCOBJ.Euclid_5p=list()
# ------------------------- Compute Power
cat("Compute Power Curve - DGP GLM - targeting alternatives \n ")
for (l in 1:length(gamvec)) {
#generate data
datl_5p =gdatGLM(n=nvec[2],gam = gamvec[l])
#--------------------------------------
#results for the Gaussian kernel
# MC_glm.type(j=1,datl=datl_5p,wmat=wmat400,Kern = "Gauss")
MCOBJ.Gauss_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Gauss")
cat("Kern=Gauss, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Gauss_5p[[l]],1,mean)); cat("\n")
#--------------------------------------
#results for the Euclidean kernel - Su & Zheng 2017
MCOBJ.Euclid_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Euclid")
cat("Kern=Euclid, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Euclid_5p[[l]],1,mean)); cat("\n")
}
rm(list=ls())
library(MASS)
library(parallel)
library(pbapply)
library(estrpac) #install from github using devtools::install_github("estsyawo/estrpac")
library(ivreg)
library(latex2exp)
library(ggplot2)
library(pstest)
#set working directory path to source file
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
#===============================================================================
#Notes:
# 1. Running time:
# 2. Peak RAM usage:
#===============================================================================
#===============================================================================
# Comments:
# Computes the size and power of the pivotal chi-squared specification test
# compared to the multiplier and wild bootstrap procedures using the Gaussian
# and the negative Euclidean Kernels
#===============================================================================
# Set Parameters
R = 1000 # set number of simulations
B=999 # number of wild bootstrap samples
levls = c(0.10,0.05,0.01) #nominal levels of the test
nvec=c(200,400,600,800) #sample sizes
gamvec=seq(0,1,by=0.2) #tuning the deviation away from the null
Sig.X = 0.25^as.matrix(dist(1:5)) #covariance matrix for generating instruments
Sig.U = 0.25^as.matrix(dist(1:2)) #covariance matrix for 1st & 2nd stage
bet = eta = rep(1,ncol(Sig.X)) #vector of coefficients on X and transforms of Z
#generate auxiliary variables for the bootstrap; n=400 fixed
wmat400=wmat.mammen(n=nvec[2],B=B,seed = 2)
Kernels=c("Gauss","Euclid") # ICM kernels to consider
cl = floor(detectCores()/2) #number of cores to use in parallel computation
#===============================================================================
source("JT05_Fonctions.R")
source("JT06_Fonctions_Sim.R")
list.files()
#===============================================================================
#===============================================================================
# *** Compute Power Curve with alternatives in mind for the chi-squared test ***
MCOBJ.Gauss_5p=MCOBJ.Euclid_5p=list()
# ------------------------- Compute Power
cat("Compute Power Curve - DGP GLM - targeting alternatives \n ")
for (l in 1:length(gamvec)) {
#generate data
datl_5p =gdatGLM(n=nvec[2],gam = gamvec[l])
#--------------------------------------
#results for the Gaussian kernel
# MC_glm.type(j=1,datl=datl_5p,wmat=wmat400,Kern = "Gauss")
MCOBJ.Gauss_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Gauss")
cat("Kern=Gauss, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Gauss_5p[[l]],1,mean)); cat("\n")
#--------------------------------------
#results for the Euclidean kernel - Su & Zheng 2017
MCOBJ.Euclid_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Euclid")
cat("Kern=Euclid, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Euclid_5p[[l]],1,mean)); cat("\n")
}
rm(list=ls())
library(MASS)
library(parallel)
library(pbapply)
library(estrpac) #install from github using devtools::install_github("estsyawo/estrpac")
library(ivreg)
library(latex2exp)
library(ggplot2)
library(pstest)
#set working directory path to source file
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
#===============================================================================
#Notes:
# 1. Running time:
# 2. Peak RAM usage:
#===============================================================================
#===============================================================================
# Comments:
# Computes the size and power of the pivotal chi-squared specification test
# compared to the multiplier and wild bootstrap procedures using the Gaussian
# and the negative Euclidean Kernels
#===============================================================================
# Set Parameters
R = 1000 # set number of simulations
B=999 # number of wild bootstrap samples
levls = c(0.10,0.05,0.01) #nominal levels of the test
nvec=c(200,400,600,800) #sample sizes
gamvec=seq(0,1,by=0.2) #tuning the deviation away from the null
Sig.X = 0.25^as.matrix(dist(1:5)) #covariance matrix for generating instruments
Sig.U = 0.25^as.matrix(dist(1:2)) #covariance matrix for 1st & 2nd stage
bet = eta = rep(1,ncol(Sig.X)) #vector of coefficients on X and transforms of Z
#generate auxiliary variables for the bootstrap; n=400 fixed
wmat400=wmat.mammen(n=nvec[2],B=B,seed = 2)
Kernels=c("Gauss","Euclid") # ICM kernels to consider
cl = floor(detectCores()/2) #number of cores to use in parallel computation
#===============================================================================
source("JT05_Fonctions.R")
source("JT06_Fonctions_Sim.R")
list.files()
#===============================================================================
#===============================================================================
# *** Compute Power Curve with alternatives in mind for the chi-squared test ***
MCOBJ.Gauss_5p=MCOBJ.Euclid_5p=list()
# ------------------------- Compute Power
cat("Compute Power Curve - DGP GLM - targeting alternatives \n ")
for (l in 1:length(gamvec)) {
#generate data
datl_5p =gdatGLM(n=nvec[2],gam = gamvec[l])
#--------------------------------------
#results for the Gaussian kernel
# MC_glm.type(j=1,datl=datl_5p,wmat=wmat400,Kern = "Gauss")
MCOBJ.Gauss_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Gauss")
cat("Kern=Gauss, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Gauss_5p[[l]],1,mean)); cat("\n")
#--------------------------------------
#results for the Euclidean kernel - Su & Zheng 2017
MCOBJ.Euclid_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Euclid")
cat("Kern=Euclid, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Euclid_5p[[l]],1,mean)); cat("\n")
}
#===============================================================================
rm(list=ls())
library(MASS)
library(parallel)
library(pbapply)
library(estrpac) #install from github using devtools::install_github("estsyawo/estrpac")
library(ivreg)
library(latex2exp)
library(ggplot2)
library(pstest)
#set working directory path to source file
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
#===============================================================================
#Notes:
# 1. Running time:
# 2. Peak RAM usage:
#===============================================================================
#===============================================================================
# Comments:
# Computes the size and power of the pivotal chi-squared specification test
# compared to the multiplier and wild bootstrap procedures using the Gaussian
# and the negative Euclidean Kernels
#===============================================================================
# Set Parameters
R = 1000 # set number of simulations
B=999 # number of wild bootstrap samples
levls = c(0.10,0.05,0.01) #nominal levels of the test
nvec=c(200,400,600,800) #sample sizes
gamvec=seq(0,1,by=0.2) #tuning the deviation away from the null
Sig.X = 0.25^as.matrix(dist(1:5)) #covariance matrix for generating instruments
Sig.U = 0.25^as.matrix(dist(1:2)) #covariance matrix for 1st & 2nd stage
bet = eta = rep(1,ncol(Sig.X)) #vector of coefficients on X and transforms of Z
#generate auxiliary variables for the bootstrap; n=400 fixed
wmat400=wmat.mammen(n=nvec[2],B=B,seed = 2)
Kernels=c("Gauss","Euclid") # ICM kernels to consider
cl = floor(detectCores()/2) #number of cores to use in parallel computation
#===============================================================================
source("JT05_Fonctions.R")
source("JT06_Fonctions_Sim.R")
list.files()
#===============================================================================
#===============================================================================
# *** Compute Power Curve with alternatives in mind for the chi-squared test ***
MCOBJ.Gauss_5p=MCOBJ.Euclid_5p=list()
# ------------------------- Compute Power
cat("Compute Power Curve - DGP GLM - targeting alternatives \n ")
for (l in 1:length(gamvec)) {
#generate data
datl_5p =gdatGLM(n=nvec[2],gam = gamvec[l])
#--------------------------------------
#results for the Gaussian kernel
# MC_glm.type(j=1,datl=datl_5p,wmat=wmat400,Kern = "Gauss")
MCOBJ.Gauss_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Gauss")
cat("Kern=Gauss, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Gauss_5p[[l]],1,mean)); cat("\n")
#--------------------------------------
#results for the Euclidean kernel - Su & Zheng 2017
MCOBJ.Euclid_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Euclid")
cat("Kern=Euclid, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Euclid_5p[[l]],1,mean)); cat("\n")
}
rm(list=ls())
library(MASS)
library(parallel)
library(pbapply)
library(estrpac) #install from github using devtools::install_github("estsyawo/estrpac")
library(ivreg)
library(latex2exp)
library(ggplot2)
library(pstest)
#set working directory path to source file
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
#===============================================================================
#Notes:
# 1. Running time:
# 2. Peak RAM usage:
#===============================================================================
#===============================================================================
# Comments:
# Computes the size and power of the pivotal chi-squared specification test
# compared to the multiplier and wild bootstrap procedures using the Gaussian
# and the negative Euclidean Kernels
#===============================================================================
# Set Parameters
R = 1000 # set number of simulations
B=999 # number of wild bootstrap samples
levls = c(0.10,0.05,0.01) #nominal levels of the test
nvec=c(200,400,600,800) #sample sizes
gamvec=seq(0,1,by=0.2) #tuning the deviation away from the null
Sig.X = 0.25^as.matrix(dist(1:5)) #covariance matrix for generating instruments
Sig.U = 0.25^as.matrix(dist(1:2)) #covariance matrix for 1st & 2nd stage
bet = eta = rep(1,ncol(Sig.X)) #vector of coefficients on X and transforms of Z
#generate auxiliary variables for the bootstrap; n=400 fixed
wmat400=wmat.mammen(n=nvec[2],B=B,seed = 2)
Kernels=c("Gauss","Euclid") # ICM kernels to consider
cl = floor(detectCores()/2) #number of cores to use in parallel computation
#===============================================================================
source("JT05_Fonctions.R")
source("JT06_Fonctions_Sim.R")
list.files()
#===============================================================================
#===============================================================================
# *** Compute Power Curve with alternatives in mind for the chi-squared test ***
MCOBJ.Gauss_5p=MCOBJ.Euclid_5p=list()
# ------------------------- Compute Power
cat("Compute Power Curve - DGP GLM - targeting alternatives \n ")
for (l in 1:length(gamvec)) {
#generate data
datl_5p =gdatGLM(n=nvec[2],gam = gamvec[l])
#--------------------------------------
#results for the Gaussian kernel
# MC_glm.type(j=1,datl=datl_5p,wmat=wmat400,Kern = "Gauss")
MCOBJ.Gauss_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Gauss")
cat("Kern=Gauss, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Gauss_5p[[l]],1,mean)); cat("\n")
#--------------------------------------
#results for the Euclidean kernel - Su & Zheng 2017
MCOBJ.Euclid_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Euclid")
cat("Kern=Euclid, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Euclid_5p[[l]],1,mean)); cat("\n")
}
#===============================================================================
#===============================================================================
# Write out results for Tex tables
n.test<- 3 #number of tests being compared
n.levels<- length(levls)#number of significance levels being considered
#column ids for empirical size at significance levels 0.1,0.05, and 0.01
id.10 = 1+(0:(n.test-1))*n.levels
id.05 = 2+(0:(n.test-1))*n.levels
id.01 = 3+(0:(n.test-1))*n.levels
#column ids for computational times in seconds
Ts<- c(n.test*n.levels+1, n.test*n.levels + 2 + (0:(n.test-2))*2)
#column ids for computational times relative to the t-test
Trel<- n.test*n.levels+1 + (1:(n.test-1))*2
#print results for the empirical size, DGP LS1: Main text
sink("tab.size.LM_1.txt") #print to file
print.size.type(MCOBJ1 = MCOBJ.Gauss_1,
MCOBJ2 = MCOBJ.Euclid_1,id=c(id.10,id.05,id.01),
Kernels=Kernels)
sink()
length(gamvec)
# plot power curve, DGP LS4
plot.pow(MCOBJ=MCOBJ.Gauss_5p,id=c(id.10,id.05,id.01),filename="PCLM_Gauss_5")
plot.pow(MCOBJ=MCOBJ.Euclid_5p,id=c(id.10,id.05,id.01),filename="PCLM_Euclid_5")
source("JT05_Fonctions.R")
source("JT06_Fonctions_Sim.R")
#===============================================================================
# Write out results for Tex tables
n.test<- 3 #number of tests being compared
n.levels<- length(levls)#number of significance levels being considered
#column ids for empirical size at significance levels 0.1,0.05, and 0.01
id.10 = 1+(0:(n.test-1))*n.levels
id.05 = 2+(0:(n.test-1))*n.levels
id.01 = 3+(0:(n.test-1))*n.levels
#column ids for computational times in seconds
Ts<- c(n.test*n.levels+1, n.test*n.levels + 2 + (0:(n.test-2))*2)
#column ids for computational times relative to the t-test
Trel<- n.test*n.levels+1 + (1:(n.test-1))*2
# plot power curve, DGP LS5
plot.pow.NLM(MCOBJ=MCOBJ.Gauss_5p,id=c(id.10,id.05,id.01),filename="PCNLM_Gauss_1")
gamvec
#===============================================================================
# Author: Feiyu Jiang & Emmanuel Selorm Tsyawo
# Project: A Consistent ICM-based χ2 Specification Test
# Date began:   Feb 03, 2022
# Last Update:  November 06, 2025
# Place:        Shanghai & Tuscaloosa
#===============================================================================
# Load packages, clear memory,
rm(list=ls())
library(MASS)
library(parallel)
library(pbapply)
library(estrpac) #install from github using devtools::install_github("estsyawo/estrpac")
library(ivreg)
library(latex2exp)
library(ggplot2)
library(pstest)
#set working directory path to source file
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
#===============================================================================
# Comments:
# Computes the size and power of the pivotal chi-squared specification test
# compared to the multiplier and wild bootstrap procedures using the Gaussian
# and the negative Euclidean Kernels
#===============================================================================
# Set Parameters
R = 1000 # set number of simulations
B=999 # number of wild bootstrap samples
levls = c(0.10,0.05,0.01) #nominal levels of the test
nvec=c(200,400,600,800) #sample sizes
gamvec=seq(0,1,by=0.2) #tuning the deviation away from the null
Sig.X = 0.25^as.matrix(dist(1:5)) #covariance matrix for generating instruments
Sig.U = 0.25^as.matrix(dist(1:2)) #covariance matrix for 1st & 2nd stage
bet = eta = rep(1,ncol(Sig.X)) #vector of coefficients on X and transforms of Z
#generate auxiliary variables for the bootstrap; n=400 fixed
wmat400=wmat.mammen(n=nvec[2],B=B,seed = 2)
Kernels=c("Gauss","Euclid") # ICM kernels to consider
cl = floor(detectCores()/2) #number of cores to use in parallel computation
#===============================================================================
source("JT05_Fonctions.R")
source("JT06_Fonctions_Sim.R")
list.files()
MCOBJ.Gauss_5p=list()
cat("Compute Power Curve - DGP GLM - targeting alternatives \n ")
l=1
datl_5p =gdatGLM(n=nvec[2],gam = gamvec[l])
MC_glm.type(j=1,datl=datl_5p,wmat=wmat400,Kern = "Gauss")
#===============================================================================
# Author: Feiyu Jiang & Emmanuel Selorm Tsyawo
# Project: A Consistent ICM-based χ2 Specification Test
# Date began:   Feb 03, 2022
# Last Update:  November 06, 2025
# Place:        Shanghai & Tuscaloosa
#===============================================================================
# Load packages, clear memory,
rm(list=ls())
library(MASS)
library(parallel)
library(pbapply)
library(estrpac) #install from github using devtools::install_github("estsyawo/estrpac")
library(ivreg)
library(latex2exp)
library(ggplot2)
library(pstest)
#set working directory path to source file
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
#===============================================================================
#Notes:
# 1. Running time:
# 2. Peak RAM usage:
#===============================================================================
#===============================================================================
# Comments:
# Computes the size and power of the pivotal chi-squared specification test
# compared to the multiplier and wild bootstrap procedures using the Gaussian
# and the negative Euclidean Kernels
#===============================================================================
# Set Parameters
R = 1000 # set number of simulations
B=999 # number of wild bootstrap samples
levls = c(0.10,0.05,0.01) #nominal levels of the test
nvec=c(200,400,600,800) #sample sizes
gamvec=seq(0,1,by=0.2) #tuning the deviation away from the null
Sig.X = 0.25^as.matrix(dist(1:5)) #covariance matrix for generating instruments
Sig.U = 0.25^as.matrix(dist(1:2)) #covariance matrix for 1st & 2nd stage
bet = eta = rep(1,ncol(Sig.X)) #vector of coefficients on X and transforms of Z
#generate auxiliary variables for the bootstrap; n=400 fixed
wmat400=wmat.mammen(n=nvec[2],B=B,seed = 2)
Kernels=c("Gauss","Euclid") # ICM kernels to consider
cl = floor(detectCores()/2) #number of cores to use in parallel computation
#===============================================================================
source("JT05_Fonctions.R")
source("JT06_Fonctions_Sim.R")
list.files()
#===============================================================================
#===============================================================================
# *** Compute Power Curve with alternatives in mind for the chi-squared test ***
MCOBJ.Gauss_5p=list()
# ------------------------- Compute Power
cat("Compute Power Curve - DGP GLM - targeting alternatives \n ")
for (l in 1:length(gamvec)) {
#generate data
datl_5p =gdatGLM(n=nvec[2],gam = gamvec[l])
#--------------------------------------
#results for the Gaussian kernel
# MC_glm.type(j=1,datl=datl_5p,wmat=wmat400,Kern = "Gauss")
MCOBJ.Gauss_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
Kern = "Gauss")
cat("Kern=Gauss, gamma = ",gamvec[l],"\n")
print(apply(MCOBJ.Gauss_5p[[l]],1,mean)); cat("\n")
#--------------------------------------
#results for the Euclidean kernel - Su & Zheng 2017
# MCOBJ.Euclid_5p[[l]]=pbsapply(1:R,MC_glm.type,datl=datl_5p,cl=cl,wmat=wmat400,
#                               Kern = "Euclid")
# cat("Kern=Euclid, gamma = ",gamvec[l],"\n")
#print(apply(MCOBJ.Euclid_5p[[l]],1,mean)); cat("\n")
}
#===============================================================================
#===============================================================================
# Write out results for Tex tables
n.test<- 3 #number of tests being compared
n.levels<- length(levls)#number of significance levels being considered
#column ids for empirical size at significance levels 0.1,0.05, and 0.01
id.10 = 1+(0:(n.test-1))*n.levels
id.05 = 2+(0:(n.test-1))*n.levels
id.01 = 3+(0:(n.test-1))*n.levels
#column ids for computational times in seconds
Ts<- c(n.test*n.levels+1, n.test*n.levels + 2 + (0:(n.test-2))*2)
#column ids for computational times relative to the t-test
Trel<- n.test*n.levels+1 + (1:(n.test-1))*2
#--------------------------------------------
# plot power curve, DGP LS5
plot.pow.NLM(MCOBJ=MCOBJ.Gauss_5p,id=c(id.10,id.05,id.01),filename="PCNLM_Gauss_1")
getwd()
list.files()
rm(list=ls())
#set working directory path to source file
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
list.files()
2*detectCores()/3
floor(2*detectCores()/3)
#===============================================================================
# Author: Feiyu Jiang & Emmanuel Selorm Tsyawo
# Project: A Consistent ICM-based χ2 Specification Test
# Date began:   Feb 03, 2022
# Last Update:  Nov 12, 2025
# Place:        Shanghai & Tuscaloosa
#===============================================================================
# Load packages, clear memory,
rm(list=ls())
#set working directory path to source file
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
list.files()
#===============================================================================
# Author: Feiyu Jiang & Emmanuel Selorm Tsyawo
# Project: A Consistent ICM-based X2 Specification Test
# Date began:   Feb 03, 2022
# Last Update:  Nov 12, 2025
# Place:        Shanghai & Tuscaloosa
#===============================================================================
# Load packages, clear memory,
rm(list=ls())
#set working directory path to source file
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
list.files()
#===============================================================================
#6.69 GB
#===============================================================================
#Simulations: Specification test
cat("Simulation - Specification Testing - Linear Models \n ")
source("JT01_MCSim_LM.R") #Time difference of 3.968907 hours
#-------------------------------------------------------------------------------
cat("Simulation - Specification Testing - Non-Linear Models \n ")
source("JT01_MCSim_NLM.R") #Time difference of ... hours
#===============================================================================
#Simulations: Test of Mean Independence
cat("Simulation - Test of Mean Independence \n ")
source("JT02_MCSim_MI.R") #Time difference of 2.445599 hours
#===============================================================================
#Simulations: Test of Mean Independence
cat("Simulation - Test of Mean Independence - Extensions \n ")
source("JT03_MCSim_MI_ext.R") #Time difference of 2.445599 hours
#===============================================================================
#Numerical Integration: Bahadur Slopes
cat("Computing Bahadur Slopes \n ")
source("JT04_Power_Comparison.R") #Time difference of 16.29027 mins
#===============================================================================
getwd()
